package net.lab1024.sa.admin.module.business.yct.ycttzq.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.yct.ycttzq.dao.AudioDao;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.entity.AudioEntity;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.form.AudioAddForm;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.form.AudioQueryForm;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.form.AudioUpdateForm;
import net.lab1024.sa.admin.module.business.yct.ycttzq.domain.vo.AudioVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 音频文件 Service
 *
 * @Author zhangben
 * @Date 2024-10-10 13:24:56
 * @Copyright 20241010
 */

@Service
public class AudioService {

    @Resource
    private AudioDao audioDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<AudioVO> queryPage(AudioQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AudioVO> list = audioDao.queryPage(page, queryForm);
        PageResult<AudioVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(AudioAddForm addForm) {
        AudioEntity audioEntity = SmartBeanUtil.copy(addForm, AudioEntity.class);
        audioDao.insert(audioEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(AudioUpdateForm updateForm) {
        AudioEntity audioEntity = SmartBeanUtil.copy(updateForm, AudioEntity.class);
        audioDao.updateById(audioEntity);
        return ResponseDTO.ok();
    }


    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        audioDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
